package net.openadventure;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import net.openadventure.animation.Animation;
import net.openadventure.hotspot.Hotspot;
import net.openadventure.location.Location;
import net.openadventure.sprites.Sprite;

public class State {

	private MouseContext mouseContext = MouseContext.ACTION;

	// The mouse activity from the last cycle
	private MouseButtonState lastMouseState = MouseButtonState.MOUSE_CLEAR;

	private int lastMouseCoordinateX = -1;

	private int lastMouseCoordinateY = -1;

	// The last Sprite that was activated by a mouse click or drag
	private int lastSpriteIndex = -1;

	private Location currentLocation = null;

	private LinkedHashMap<String, Location> locations = new LinkedHashMap<String, Location>();

	// The list of all items currently being drawn on the screen
	private LinkedHashMap<String, Sprite> sprites = new LinkedHashMap<String, Sprite>();

	private LinkedHashMap<String, Animation> animations = new LinkedHashMap<String, Animation>();

	// private static State instance = null;

	private List<Hotspot> activeEgoHotspots = new ArrayList<Hotspot>();

	public State() {
	}

	// public static synchronized State getInstance() {
	// if(instance == null) {
	// instance = new State();
	// }
	// return instance;
	// }

	// public synchronized void addSprite(String name, Sprite sprite) {
	// sprites.put(name, sprite);
	// }

	// public synchronized void removeSprite(String name) {
	// sprites.remove(name);
	// }
	//	
	// public synchronized Sprite getSprite(int i) {
	// return sprites.get(i);
	// }
	//	
	// public synchronized Sprite getSprite(String name) {
	// return sprites.get(name);
	// }
	//	
	// public synchronized int getNumberOfSprites() {
	// return sprites.size();
	// }
	//	
	// public synchronized void removeAllSprites() {
	// sprites = new LinkedHashMap<String, Sprite>();
	// }

	public synchronized LinkedHashMap<String, Sprite> getSprites() {
		// return (LinkedHashMap)sprites.clone();
		return sprites;
	}

	public synchronized LinkedHashMap<String, Animation> getAnimations() {
		// return (LinkedHashMap)sprites.clone();
		return animations;
	}

	public MouseButtonState getLastMouseState() {
		return lastMouseState;
	}

	public void setLastMouseState(MouseButtonState lastMouseState) {
		this.lastMouseState = lastMouseState;
	}

	public MouseContext getMouseContext() {
		return mouseContext;
	}

	public void setMouseContext(MouseContext mouseContext) {
		this.mouseContext = mouseContext;
	}

	public int getLastMouseCoordinateX() {
		return lastMouseCoordinateX;
	}

	public void setLastMouseCoordinateX(int lastMouseCoordinateX) {
		this.lastMouseCoordinateX = lastMouseCoordinateX;
	}

	public int getLastMouseCoordinateY() {
		return lastMouseCoordinateY;
	}

	public void setLastMouseCoordinateY(int lastMouseCoordinateY) {
		this.lastMouseCoordinateY = lastMouseCoordinateY;
	}

	public int getLastSpriteIndex() {
		return lastSpriteIndex;
	}

	public void setLastSpriteIndex(int lastSpriteIndex) {
		this.lastSpriteIndex = lastSpriteIndex;
	}

	public Location getCurrentLocation() {
		return currentLocation;
	}

	public void setCurrentLocation(Location currentLocation) {
		this.currentLocation = currentLocation;
	}

	public void addLocation(String name, Location location) {
		// Check parameters
		if (name == null && location == null) {
			throw new NullPointerException(
					"Parameters name and location can not be null.");
		} else if (name == null) {
			throw new NullPointerException("Parameter name can not be null.");
		} else if (location == null) {
			throw new NullPointerException(
					"Parameter location can not be null.");
		}

		locations.put(name, location);
		currentLocation = location;
	}

	public Location getLocation(String name) {
		return locations.get(name);
	}

	public List<Hotspot> getActiveEgoHotspots() {
		return activeEgoHotspots;
	}

	// public Ego getEgo() {
	// return ego;
	// }
	//
	// public void setEgo(Ego ego) {
	// this.ego = ego;
	// }
}
